package org.dandsoft.blackbox.knowledge;

import org.jdom.Element;
import org.jdom.Attribute;

/**
 * User: dvilyuzhanin
 * Date: 14.01.2009 18:51:08
 */
public class XMLUtil {


    public static Element createElement(Element rootElement, String name, String content, Attribute... attributes) {
        Element element = new Element(name);
        if (content != null && content.length() > 0) {
            element.addContent(content);
        }
        if (attributes != null) {
            for (Attribute attr : attributes) {
                element.setAttribute(attr);
            }
        }

        if (rootElement != null) {
            rootElement.addContent(element);
        }

        return element;
    }

    public static void assertElement(Element element, String name) throws Exception {
        if (!name.equals(element.getName())) {
            throw new Exception("Wrong element name: name = " + element.getName() + ", needName = " + name);
        }
    }

    


}
